//
//  FortuneTableViewCell.m
//  Contractor
//
//  Created by 金鑫 on 16/5/16.
//  Copyright © 2016年 star j. All rights reserved.
//

#import "FortuneTableViewCell.h"
#import "CellBackground.h"
#import "CONST.h"

@implementation FortuneTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        CGFloat length = __kScreenWidth / 4.0f ;
        //年月
        self.yearLabel = [self creatlabel:14.0f color:[UIColor blackColor]] ;
        self.yearLabel.frame = CGRectMake(0, 10, length, 14.0f) ;
        //日期
        self.dayLabel = [self creatlabel:14.0f color:[UIColor blackColor]] ;
        self.dayLabel.frame = CGRectMake(0, 26, length, 14.0f) ;
        //操作
        self.doLabel = [self creatlabel:16.0f color:[UIColor blackColor]] ;
        self.doLabel.frame = CGRectMake(length, 16, length, 18.0f) ;
        //金额
        self.amountLabel = [self creatlabel:16.0f color:[UIColor orangeColor]] ;
        self.amountLabel.frame = CGRectMake(length * 3, 16, length, 18.0f) ;
        //背景图
        CellBackground *backView = [[CellBackground alloc] initWithFrame:CGRectMake(0, 0, __kScreenWidth, 50)] ;
        backView.backgroundColor = [UIColor whiteColor] ;
        [self.contentView addSubview:backView] ;
        self.backView = backView ;
        [self.backView addSubview:self.yearLabel] ;
        [self.backView addSubview:self.dayLabel] ;
        [self.backView addSubview:self.doLabel] ;
        [self.backView addSubview:self.amountLabel] ;
    }
    return self ;
}

//创建label
- (UILabel *)creatlabel:(CGFloat) size color:(UIColor *)color
{
    UILabel *label = [[UILabel alloc] init] ;
    label.font = [UIFont fontWithName:@"AvenirLTStd-Light" size:size] ;
    label.backgroundColor = [UIColor clearColor] ;
    label.textAlignment = NSTextAlignmentCenter ;
    label.textColor = color ;
    [self.contentView addSubview:label] ;
    return label ;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"cellID" ;
    FortuneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier] ;
    if (!cell) {
        cell = [[FortuneTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] ;
    }
    return cell ;
}

- (void)config:(ModelContent *)model
{
    self.backgroundColor = [UIColor whiteColor] ;
    
    self.yearLabel.text = [model.inputdatetime substringToIndex:10] ;
    self.dayLabel.text = [model.inputdatetime substringWithRange:NSMakeRange(model.inputdatetime.length-8, 8)] ;
    self.doLabel.text = model.flowtype ;
    NSString *moneyStr = [model.money substringWithRange:NSMakeRange(0, 1)] ;
    NSLog(@"%@",moneyStr) ;
    if ([moneyStr isEqualToString:@"-"]) {
        self.amountLabel.textColor = [UIColor redColor] ;
        self.amountLabel.text = [NSString stringWithFormat:@"%@",model.money] ;

    }
    else{
        self.amountLabel.text = [NSString stringWithFormat:@"+%@",model.money] ;
    }

}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
